<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseCharges {

	protected $m_bigintId;
	protected $m_intChargeTypeId;
	protected $m_intChargeCatagoryId;
	protected $m_intMinAmount;
	protected $m_intMaxAmount;
	protected $m_intRate;
	protected $m_intDepartmentId;
	protected $m_intPatientId;
	protected $m_intReferanceId;
	protected $m_intDeletedBy;
	protected $m_strDeletedOn;
	protected $m_intCreatedBy;
	protected $m_strCreatedOn;
	protected $m_intUpdatedBy;
	protected $m_strUpdatedOn;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_bigintId;
	}

	public function getChargeTypeId(){
		return $this->m_intChargeTypeId;
	}

	public function getChargeCatagoryId(){
		return $this->m_intChargeCatagoryId;
	}

	public function getMinAmount(){
		return $this->m_intMinAmount;
	}

	public function getMaxAmount(){
		return $this->m_intMaxAmount;
	}

	public function getRate(){
		return $this->m_intRate;
	}

	public function getDepartmentId(){
		return $this->m_intDepartmentId;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getReferanceId(){
		return $this->m_intReferanceId;
	}

	public function getDeletedBy(){
		return $this->m_intDeletedBy;
	}

	public function getDeletedOn(){
		return $this->m_strDeletedOn;
	}

	public function getCreatedBy(){
		return $this->m_intCreatedBy;
	}

	public function getCreatedOn(){
		return $this->m_strCreatedOn;
	}

	public function getUpdatedBy(){
		return $this->m_intUpdatedBy;
	}

	public function getUpdatedOn(){
		return $this->m_strUpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_bigintId = $Id;
	}

	public function setChargeTypeId( $ChargeTypeId ){
		$this->m_intChargeTypeId = $ChargeTypeId;
	}

	public function setChargeCatagoryId( $ChargeCatagoryId ){
		$this->m_intChargeCatagoryId = $ChargeCatagoryId;
	}

	public function setMinAmount( $MinAmount ){
		$this->m_intMinAmount = $MinAmount;
	}

	public function setMaxAmount( $MaxAmount ){
		$this->m_intMaxAmount = $MaxAmount;
	}

	public function setRate( $Rate ){
		$this->m_intRate = $Rate;
	}

	public function setDepartmentId( $DepartmentId ){
		$this->m_intDepartmentId = $DepartmentId;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setReferanceId( $ReferanceId ){
		$this->m_intReferanceId = $ReferanceId;
	}

	public function setDeletedBy( $DeletedBy ){
		$this->m_intDeletedBy = $DeletedBy;
	}

	public function setDeletedOn( $DeletedOn ){
		$this->m_strDeletedOn = $DeletedOn;
	}

	public function setCreatedBy( $CreatedBy ){
		$this->m_intCreatedBy = $CreatedBy;
	}

	public function setCreatedOn( $CreatedOn ){
		$this->m_strCreatedOn = $CreatedOn;
	}

	public function setUpdatedBy( $UpdatedBy ){
		$this->m_intUpdatedBy = $UpdatedBy;
	}

	public function setUpdatedOn( $UpdatedOn ){
		$this->m_strUpdatedOn = $UpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into CHARGES (charge_type_id, charge_catagory_id, min_amount, max_amount, rate, department_id, patient_id, referance_id, deleted_by, deleted_on, created_by, created_on, updated_by, updated_on) values (" . $this->getChargeTypeId() . ", " . $this->getChargeCatagoryId() . ", " . $this->getMinAmount() . ", " . $this->getMaxAmount() . ", " . $this->getRate() . ", " . $this->getDepartmentId() . ", " . $this->getPatientId() . ", " . $this->getReferanceId() . ", " . $this->getDeletedBy() . ", '" . $this->getDeletedOn() . "', " . $this->getCreatedBy() . ", now() , " . $this->getUpdatedBy() . ", NULL )");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE CHARGES set  charge_type_id= " . $this->getChargeTypeId() . ", charge_catagory_id= " . $this->getChargeCatagoryId() . ", min_amount= " . $this->getMinAmount() . ", max_amount= " . $this->getMaxAmount() . ", rate= " . $this->getRate() . ", department_id= " . $this->getDepartmentId() . ", patient_id= " . $this->getPatientId() . ", referance_id= " . $this->getReferanceId() . ", deleted_by= " . $this->getDeletedBy() . ", deleted_on= '" . $this->getDeletedOn() . "', created_by= " . $this->getCreatedBy() . ", updated_by= " . $this->getUpdatedBy() . ",updated_on = now()  where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM charges WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'charges'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}